package com.demo.core.service.exception.base;

/**
 * 对象已存在异常
 * 
 * @author ryuu.kk
  */
public class ObjectAlreadyExistedException extends RuntimeException {

	/**
	 * 序列化对象
	 */
	private static final long serialVersionUID = -2589782557087456001L;
	/**
	 * 异常对象
	 */
	private final Object object;
	
	/**
	 * 国家化消息
	 */
	private String i18n;
	
	/**
	 * 构造函数
	 * @param target 异常对象
	 * @param message 异常消息
	 */
	public ObjectAlreadyExistedException(Object target, String message, String i18nCode) {
		super(message);
		this.object = target;
		this.i18n = i18nCode;
	}
	
	/**
	 * 构造函数
	 * @param target 异常对象
	 * @param message 异常消息
	 */
	public ObjectAlreadyExistedException(Object target, String message) {
		super(message);
		this.object = target;
	}
	/**
	 * 构造函数
	 * @param target 异常对象
	 * @param message 异常消息
	 * @param cause Throwable
	 */
	public ObjectAlreadyExistedException(Object target, String message, Throwable cause) {
		super(message, cause);
		this.object = target;
	}
	
	public Object getObject() {
		return object;
	}
	
	public String getI18n() {
		if (i18n == null) {
			i18n = getMessage();
		}
		return i18n;
	}
	public void setI18n(String i18n) {
		this.i18n = i18n;
	}
}
